home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / plugin / gamelib / shadow.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-28  |  1.9 KB  |  93 lines

  1. #include "..\..\lib\Fly3D.h"
  2. #include "gamelib.h"
  3.  
  4. void shadow::reposition(bsp_object *obj)
  5. {
  6.     curobj=obj;
  7.     flyengine->excludecollision=obj;
  8.     hit=flyengine->collision_bsp(flyengine->bsp,obj->pos,obj->pos+vector(0,0,-flyengine->bboxdiag),TYPE_STATIC_MESH);
  9.     flyengine->excludecollision=0;
  10.     if(hit)
  11.     {
  12.         pos=flyengine->hitip+flyengine->hitmesh->faces[flyengine->hitface]->normal;
  13.         align_z(flyengine->hitmesh->faces[flyengine->hitface]->normal);
  14.     }
  15. }
  16.  
  17. void shadow::draw_simple_shadow()
  18. {
  19.     glDepthMask(GL_FALSE);
  20.     glBlendFunc(GL_ZERO,GL_ONE_MINUS_SRC_COLOR);
  21.     glDisable(GL_DEPTH_TEST);
  22.  
  23.     glColor3f(
  24.         1.0f-flyengine->shadowcolor.x,
  25.         1.0f-flyengine->shadowcolor.y,
  26.         1.0f-flyengine->shadowcolor.z);
  27.  
  28.     tc->use(texture);
  29.  
  30.     static vector x,y;
  31.     x=X*sizex;
  32.     y=Y*sizey;
  33.  
  34.     glBegin(GL_QUADS);
  35.  
  36.     glTexCoord2f(1,0);
  37.     glVertex3f(pos.x+x.x-y.x, pos.y+x.y-y.y, pos.z+x.z-y.z);
  38.  
  39.     glTexCoord2f(1,1);
  40.     glVertex3f(pos.x+x.x+y.x, pos.y+x.y+y.y, pos.z+x.z+y.z);
  41.  
  42.     glTexCoord2f(0,1);
  43.     glVertex3f(pos.x+y.x-x.x, pos.y+y.y-x.y, pos.z+y.z-x.z);
  44.  
  45.     glTexCoord2f(0,0);
  46.     glVertex3f(pos.x-x.x-y.x, pos.y+-x.y-y.y, pos.z-x.z-y.z);
  47.  
  48.     glEnd();
  49.  
  50.     glEnable(GL_DEPTH_TEST);
  51.     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  52.     glDepthMask(GL_TRUE);
  53. }
  54.  
  55. void shadow::draw()
  56. {
  57.     flyengine->excludecollision=curobj;
  58.     if (flyengine->collision_test(flyengine->bsp,flyengine->cam->pos,pos))
  59.     if (flyengine->hitobj!=flyengine->cam)
  60.         {
  61.         flyengine->excludecollision=0;
  62.         return;
  63.         }
  64.     flyengine->excludecollision=0;
  65.  
  66.     if(hit)
  67.         draw_simple_shadow();
  68. }
  69.  
  70. int shadow::get_custom_param_desc(int i,param_desc *pd)
  71. {
  72.     if (pd!=0)
  73.     switch(i)
  74.     {
  75.     case 0:
  76.         pd->type='p';
  77.         pd->data=&texture;
  78.         strcpy(pd->name,"texture");
  79.         break;
  80.     case 1: 
  81.         pd->type='f';
  82.         pd->data=&sizex;
  83.         strcpy(pd->name,"sizex");
  84.         break;
  85.     case 2: 
  86.         pd->type='f';
  87.         pd->data=&sizey;
  88.         strcpy(pd->name,"sizey");
  89.         break;
  90.     }
  91.     return 3;
  92. }
  93.